Conditions | 9 |
Paths | 96 |
Total Lines | 158 |
Lines | 0 |
Ratio | 0 % |
Changes | 17 | ||
Bugs | 1 | Features | 3 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /*jslint |
||
375 | function initialize(xcenter, xzoom, xmap, xfeatures, xmarkers, xlines, xgeocache) { |
||
376 | 'use strict'; |
||
377 | |||
378 | var center, |
||
379 | //atDefaultCenter = false, |
||
380 | zoom = parseInt(xzoom, 10), |
||
381 | maptype = xmap, |
||
382 | loadfromcookies = false, |
||
383 | markerdata = parseMarkersFromUrl(xmarkers), |
||
384 | markercenter = null, |
||
385 | clat = 0, |
||
386 | clon = 0; |
||
387 | if (markerdata.length > 0) { |
||
388 | markerdata.map(function (m) { |
||
389 | clat += m.coords.lat(); |
||
390 | clon += m.coords.lng(); |
||
391 | }); |
||
392 | markercenter = new google.maps.LatLng(clat / markerdata.length, clon / markerdata.length); |
||
393 | } |
||
394 | |||
395 | if (xcenter && xcenter !== '') { |
||
396 | center = parseCenterFromUrl(xcenter); |
||
397 | } else if (markercenter) { |
||
398 | center = markercenter; |
||
399 | } else { |
||
400 | loadfromcookies = true; |
||
401 | |||
402 | /* try to read coordinats from cookie */ |
||
403 | clat = get_cookie_float('clat', CLAT_DEFAULT); |
||
404 | clon = get_cookie_float('clon', CLON_DEFAULT); |
||
405 | //if (clat === CLAT_DEFAULT && clon === CLON_DEFAULT) { |
||
406 | // atDefaultCenter = true; |
||
407 | //} |
||
408 | |||
409 | clat = repairLat(clat, CLAT_DEFAULT); |
||
410 | clon = repairLon(clon, CLON_DEFAULT); |
||
411 | center = new google.maps.LatLng(clat, clon); |
||
412 | |||
413 | zoom = get_cookie_int('zoom', ZOOM_DEFAULT); |
||
414 | maptype = get_cookie_string('maptype', MAPTYPE_DEFAULT); |
||
415 | } |
||
416 | |||
417 | if (!center) { |
||
418 | center = new google.maps.LatLng(CLAT_DEFAULT, CLON_DEFAULT); |
||
419 | //atDefaultCenter = true; |
||
420 | } |
||
421 | |||
422 | zoom = repairZoom(zoom, ZOOM_DEFAULT); |
||
423 | maptype = repairMaptype(maptype, MAPTYPE_DEFAULT); |
||
424 | map = new google.maps.Map( |
||
425 | document.getElementById("themap"), |
||
426 | { |
||
427 | zoom: zoom, |
||
428 | center: center, |
||
429 | scaleControl: true, |
||
430 | streetViewControl: false, |
||
431 | mapTypeControlOptions: { mapTypeIds: ['OSM', 'OSM/DE', 'OCM', 'OUTD', 'TOPO', google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.TERRAIN] }, |
||
432 | mapTypeId: google.maps.MapTypeId.ROADMAP |
||
433 | } |
||
434 | ); |
||
435 | |||
436 | map.mapTypes.set("OSM", osmProvider("OSM")); |
||
437 | map.mapTypes.set("OSM/DE", osmDeProvider("OSM/DE")); |
||
438 | map.mapTypes.set("OCM", ocmProvider("OCM")); |
||
439 | map.mapTypes.set("OUTD", thunderforestOutdoorsProvider("OUTD")); |
||
440 | map.mapTypes.set("TOPO", opentopomapProvider("TOPO")); |
||
441 | map.setMapTypeId(maptype); |
||
442 | |||
443 | Attribution.init(map); |
||
444 | Sidebar.init(map); |
||
445 | ExternalLinks.init(map); |
||
446 | Markers.init(map); |
||
447 | Lines.init(map); |
||
448 | Geolocation.init(map); |
||
449 | Hillshading.init(map); |
||
450 | NPA.init(map); |
||
451 | CDDA.init(map); |
||
452 | Freifunk.init(map); |
||
453 | Okapi.init(map); |
||
454 | |||
455 | //boundariesLayer = new google.maps.ImageMapType({ |
||
456 | // getTileUrl: function(coord, zoom) { |
||
457 | // if (6 <= zoom && zoom <= 16) |
||
458 | // { |
||
459 | // return tileUrl("http://korona.geog.uni-heidelberg.de/tiles/adminb/?x=%x&y=%y&z=%z", ["dummy"], coord, zoom); |
||
460 | // } |
||
461 | // else |
||
462 | // { |
||
463 | // return null; |
||
464 | // } |
||
465 | // }, |
||
466 | // tileSize: new google.maps.Size(256, 256), |
||
467 | // name: "adminb", |
||
468 | // alt: "Administrative Boundaries", |
||
469 | // maxZoom: 16 }); |
||
470 | |||
471 | map.setCenter(center, zoom); |
||
472 | |||
473 | google.maps.event.addListener(map, "center_changed", function () { |
||
474 | storeZoom(); |
||
475 | storeCenter(); |
||
476 | }); |
||
477 | google.maps.event.addListener(map, "zoom_changed", function () { |
||
478 | storeZoom(); |
||
479 | storeCenter(); |
||
480 | }); |
||
481 | google.maps.event.addListener(map, "maptypeid_changed", function () { |
||
482 | storeMapType(); |
||
483 | }); |
||
484 | |||
485 | if (loadfromcookies) { |
||
486 | parseMarkersFromCookies().map(function (m) { |
||
487 | Markers.newMarker(m.coords, m.id, m.r, m.name); |
||
488 | }); |
||
489 | |||
490 | parseLinesFromCookies().map(function (m) { |
||
491 | Lines.newLine(m.source, m.target); |
||
492 | }); |
||
493 | } else { |
||
494 | markerdata.map(function (m) { |
||
495 | Markers.newMarker(m.coords, m.id, m.r, m.name); |
||
496 | }); |
||
497 | |||
498 | parseLinesFromUrl(xlines).map(function (m) { |
||
499 | Lines.newLine(m.source, m.target); |
||
500 | }); |
||
501 | } |
||
502 | |||
503 | Okapi.setShowCache(xgeocache); |
||
504 | Sidebar.restore(true); |
||
505 | xfeatures = xfeatures.toLowerCase(); |
||
506 | if (xfeatures === '[default]') { |
||
507 | Hillshading.restore(false); |
||
508 | //restoreBoundaries(false); |
||
509 | Okapi.restore(false); |
||
510 | NPA.toggle(false); |
||
511 | CDDA.toggle(false); |
||
512 | Freifunk.toggle(false); |
||
513 | } else { |
||
514 | Hillshading.toggle(xfeatures.indexOf('h') >= 0); |
||
515 | //toggleBoundaries(xfeatures.indexOf('b') >= 0); |
||
516 | Okapi.toggle(xfeatures.indexOf('g') >= 0); |
||
517 | NPA.toggle(xfeatures.indexOf('n') >= 0); |
||
518 | Freifunk.toggle(xfeatures.indexOf('f') >= 0); |
||
519 | } |
||
520 | restoreCoordinatesFormat("DM"); |
||
521 | |||
522 | if (xgeocache !== "") { |
||
523 | Okapi.toggle(true); |
||
524 | //atDefaultCenter = false; |
||
525 | } |
||
526 | |||
527 | Attribution.forceUpdate(); |
||
528 | |||
529 | //if (atDefaultCenter) { |
||
530 | // Geolocation.whereAmI(); |
||
531 | //} |
||
532 | } |
||
533 |